package com.etime.shuhuiyuan.services.teacher.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shuhuiyuan.dao.TeacherDao;
import com.etime.shuhuiyuan.pojo.Teacher;
import com.etime.shuhuiyuan.services.teacher.interfaces.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherDao teacherDao;

    @Override
    public int insertTeacher(Teacher teacher) {
        return teacherDao.insert(teacher);
    }

    @Override
    public int updateTeacher(Teacher teacher) {
        return teacherDao.updateById(teacher);
    }

    @Override
    public List<Teacher> selectTeacherList(Teacher teacher) {
        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        if (teacher != null && teacher.getTectitle() != null && !teacher.getTectitle().equalsIgnoreCase("")){
            wrapper.eq("tectitle",teacher.getTectitle());
        }
        return teacherDao.selectList(wrapper);
    }

    @Override
    public Page<Teacher> selectTeacherByPage(Teacher teacher, long pageNum, long pageSize) {
        Page<Teacher> page = new Page<>(pageNum,pageSize);
        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        if (teacher!=null && teacher.getTectitle()!=null && !teacher.getTectitle().equalsIgnoreCase("")){
            wrapper.eq("tectitle",teacher.getTectitle());
        }
        return teacherDao.selectPage(page,wrapper);
    }

    @Override
    public Teacher selectTeacherById(Integer teacherId) { return teacherDao.selectById(teacherId); }
}
